package com.xn.studydeom.controller;

/**
 * @author xn
 * @date 2022/11/23 7:22
 */

import com.xn.studydeom.config.SimpleMQConfig;
import com.xn.studydeom.pojo.Order;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * simple模式的MQ
 *
 * @author jaymin
 * 2020/12/30 17:42
 */
@RestController
public class SimpleProducerController {

    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * 发生消息到RabbitMQ,使用SpringBoot默认的交换机<br>
     *
     * @param message
     */
    @PostMapping("/sendSimpleMessage")
    public void sendSimpleMessage(String message) {
        rabbitTemplate.convertAndSend(SimpleMQConfig.SIMPLE_QUEUE_NAME, message);
    }

    /**
     * 消息体为对象。配置MessageConverter为Jackson2JsonMessageConverter即可
     * @param order
     */
    @PostMapping("/sendSimpleOrderMessage")
    public void sendSimpleOrderMessage(@RequestBody Order order){
        rabbitTemplate.convertAndSend(SimpleMQConfig.HANDLER_OBJECT_QUEUE_NAME, order);
    }
}
